import {Controller, Get, Post, Body, Patch, Param, Delete, Inject} from '@nestjs/common';
import {TestService} from './test.service';
import {CreateTestDto} from './dto/create-test.dto';
import {UpdateTestDto} from './dto/update-test.dto';
import {MySql2Database} from "drizzle-orm/mysql2";
import {userTable,User} from "../../database/drizzle/schema/user.schema";
import {eq} from "drizzle-orm";

@Controller('test')
export class TestController {
    constructor(private readonly testService: TestService,@Inject('DRIZZLE_ORM') private readonly drizzle:MySql2Database) {
    }

    @Post()
    create(@Body() createTestDto: CreateTestDto) {
        return this.testService.create(createTestDto);
    }

    @Get()
    async findAll() {
    // await this.drizzle.insert(userTable).values( {
    //         user_name: 'test1',
    //         nick_name: 'test1',
    //     })
        await this.drizzle
            .update(userTable)
            .set({ user_name: 'testddddddd' ,update_time: new Date()})
            .where(eq(userTable.user_name, 'test'));
      // const res=  await this.drizzle.select().from(userTable)

        return await this.drizzle.select().from(userTable)
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.testService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateTestDto: UpdateTestDto) {
        return this.testService.update(+id, updateTestDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.testService.remove(+id);
    }
}
